﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

using System.Collections.Generic;
using BPM.Foundation.WFService;
using BPM.Base.WFLib.CustomerAttribute;

namespace BPM.Base.WFLib
{
    [System.Drawing.ToolboxBitmap(typeof(函数), "pic.foun.png")]
    public partial class 函数 : Activity
    {
        //

        //
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                switch (运算符)
                {
                    case "存在于":
                        if (右表达式.Contains(左表达式))
                        {
                            运算结果 = "存在";
                        }
                        else
                        {
                            运算结果 = "不存在";
                        }
                        break;

                    case "字符比效":
                        if (左表达式 == 右表达式)
                        {
                            运算结果 = "等于";
                        }
                        else
                        {
                            运算结果 = "不等于";
                        }
                        break;

                    case "数值比效":
                        double x = double.Parse(左表达式);
                        double y = double.Parse(右表达式);

                        if (x == y)
                        {
                            运算结果 = "等于";
                        }

                        if (x >=y)
                        {
                            运算结果 = "大于等于";
                        }

                        if (x < y)
                        {
                            运算结果 = "小于";
                        }


                        break;

                    case "加":
                        double x1 = double.Parse(左表达式);
                        double y1 = double.Parse(右表达式);
                        运算结果 = (x1 + y1).ToString();
                        break;

                    case "减":
                        double x2 = double.Parse(左表达式);
                        double y2 = double.Parse(右表达式);
                        运算结果 = (x2 - y2).ToString();
                        break;

                    case "乘":
                        double x3 = double.Parse(左表达式);
                        double y3 = double.Parse(右表达式);
                        运算结果 = (x3 * y3).ToString();
                        break;

                    case "除":
                        double x4 = double.Parse(左表达式);
                        double y4 = double.Parse(右表达式);
                        运算结果 = (x4 / y4).ToString();
                        break;


                    default :
                        运算结果 = "err";
                        break;
                }

                return base.Execute(executionContext);
            }
            catch
            {

                运算结果 = "err";
                return base.Execute(executionContext);
            }
        }


        //-[左表达式]
        public static DependencyProperty 左表达式Property = DependencyProperty.Register("左表达式", typeof(string), typeof(函数), new PropertyMetadata(""));

        [DescriptionAttribute("")]
        [CategoryAttribute("")]
        [BrowsableAttribute(true)]
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        public string 左表达式
        {
            get
            {
                return ((string)(base.GetValue(函数.左表达式Property)));
            }
            set
            {
                base.SetValue(函数.左表达式Property, value);
            }
        }

        //-[右表达式]
        public static DependencyProperty 右表达式Property = DependencyProperty.Register("右表达式", typeof(string), typeof(函数), new PropertyMetadata(""));

        [DescriptionAttribute("")]
        [CategoryAttribute("")]
        [BrowsableAttribute(true)]
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        public string 右表达式
        {
            get
            {
                return ((string)(base.GetValue(函数.右表达式Property)));
            }
            set
            {
                base.SetValue(函数.右表达式Property, value);
            }
        }



        //-[运算符] //[数值:加,减,乘,除],[数值,日期:比效],[字符串:存在于],
        public static DependencyProperty 运算符Property = DependencyProperty.Register("运算符", typeof(string), typeof(函数), new PropertyMetadata(""));

        [DescriptionAttribute("")]
        [CategoryAttribute("")]
        [BrowsableAttribute(true)]
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [EditorAttribute(typeof(函数_运算符), typeof(System.Drawing.Design.UITypeEditor))]
        public string 运算符
        {
            get
            {
                return ((string)(base.GetValue(函数.运算符Property)));
            }
            set
            {
                base.SetValue(函数.运算符Property, value);
            }
        }

        //-[运算结果] //[加,减,乘,除:值],[比效:等于,不等于],[存在于:存在,不存在]
        public static DependencyProperty 运算结果Property = DependencyProperty.Register("运算结果", typeof(string), typeof(函数), new PropertyMetadata(""));

        [DescriptionAttribute("")]
        [CategoryAttribute("")]
        [BrowsableAttribute(true)]
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        public string 运算结果
        {
            get
            {
                return ((string)(base.GetValue(函数.运算结果Property)));
            }
            set
            {
                base.SetValue(函数.运算结果Property, value);
            }
        }

    }
}
